<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加客户</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/font-awesome.css">
</head>

<body>

    <jsp:include page="/WEB-INF/jsp/head.jsp"></jsp:include>
    <jsp:include page="/WEB-INF/jsp/aside.jsp"></jsp:include>

    <!-- 内容区域 -->
    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>客户管理</h1>
            <ol class="breadcrumb">
                <li>
                    <a href="index.html">
                        <i class="fa fa-dashboard"></i> 首页
                    </a>
                </li>
                <li>
                    <a href="all-order-manage-list.html">客户管理</a>
                </li>
                <li class="active">添加客户</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!--客户信息-->
            <div class="panel panel-default">
                <div class="panel-heading">更新客户信息</div>
                <!-- <form action="${pageContext.request.contextPath }/updateCustomer.action" method="POST" onsubmit="return check()"> -->
                <input id="cust_id" type="hidden" name="cust_id" value="${customer.cust_id }" />
                <div class="row data-type">

                    <div class="col-md-2 title">客户名称</div>
                    <div class="col-md-10 data text">
                        <input id="cust_name" type="text" name="cust_name" class="form-control" placeholder="客户名称"
                            value="${customer.cust_name }">
                    </div>

                    <div class="col-md-2 title">客户来源</div>
                    <div class="col-md-10 data">
                        <select id="cust_source" name="cust_source" class="form-control" style="height:36px">
                            <c:forEach items="${fromType }" var="item">
                                <option value="${item.dict_id }" <c:if test="${item.dict_id == customer.cust_source}">selected</c:if>>
                                    ${item.dict_item_name }
                                </option>
                            </c:forEach>
                        </select>
                    </div>

                    <div class="col-md-2 title">所属行业</div>
                    <div class="col-md-10 data text">
                        <select id="cust_industry" name="cust_industry" class="form-control" style="height:36px">
                            <option value="">请选择</option>
                            <c:forEach items="${industryType }" var="item">
                                <option value="${item.dict_id }" <c:if test="${item.dict_id == customer.cust_industry}">selected</c:if>>
                                    ${item.dict_item_name }
                                </option>
                            </c:forEach>
                        </select>
                    </div>

                    <div class="col-md-2 title">客户级别</div>
                    <div class="col-md-10 data text">
                        <select id="cust_level" name="cust_level" class="form-control" style="height:36px">
                            <option value="">请选择</option>
                            <c:forEach items="${levelType }" var="item">
                                <option value="${item.dict_id }" <c:if test="${item.dict_id == customer.cust_level}">selected</c:if>>
                                    ${item.dict_item_name }
                                </option>
                            </c:forEach>
                        </select>
                    </div>

                    <div class="col-md-2 title">联系人</div>
                    <div class="col-md-10 data line-height36">
                        <input id="cust_linkman" type="text" name="cust_linkman" class="form-control" placeholder="联系人"
                            value="${customer.cust_linkman }">
                    </div>

                    <div class="col-md-2 title">固定电话</div>
                    <div class="col-md-10 data">
                        <input id="cust_phone" type="text" name="cust_phone" class="form-control" placeholder="固定电话"
                            value="${customer.cust_phone }">
                    </div>

                    <div class="col-md-2 title">移动电话</div>
                    <div class="col-md-10 data">
                        <input id="cust_mobile" type="text" name="cust_mobile" class="form-control" placeholder="移动电话"
                            value="${customer.cust_mobile }">
                    </div>

                    <div class="col-md-2 title">邮政编码</div>
                    <div class="col-md-10 data">
                        <input id="cust_zipcode" type="text" name="cust_zipcode" class="form-control" placeholder="邮政编码"
                            value="${customer.cust_zipcode }">
                    </div>

                    <div class="col-md-2 title">联系地址</div>
                    <div class="col-md-10 data">
                        <input id="cust_address" type="text" name="cust_address" class="form-control" placeholder="联系地址"
                            value="${customer.cust_address }">
                    </div>
                </div>

                <!--工具栏-->
                <div class="box-tools text-center" style="margin-bottom: 10px;">
                    <!-- <input type="submit" class="btn bg-maroon" value="确认修改" /> -->
                    <button type="button" class="btn bg-maroon" onclick="updateCustomer()">确认修改</button>
                    <button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
                </div>
                <!--工具栏/-->

                <!-- </form> -->
            </div>
            <!--客户信息/-->

        </section>
        <!-- 正文区域 /-->                                                      

    </div>
    <!-- 内容区域 /-->

    <script>

    console.log("url = "+document.referrer)

        // 修改客户信息表单提交验证
        function updateCustomer() {
            var cust_id = $("#cust_id").val();
            var cust_name = $("#cust_name").val();
            var cust_source = $("#cust_source").val();
            var cust_industry = $("#cust_industry").val();
            var cust_level = $("#cust_level").val();
            var cust_linkman = $("#cust_linkman").val();
            var cust_phone = $("#cust_phone").val();
            var cust_mobile = $("#cust_mobile").val();
            var cust_zipcode = $("#cust_zipcode").val();
            var cust_address = $("#cust_address").val();
            console.log("updateCustomer run");
            console.log("cust_id = " + cust_id);
            console.log("cust_name = " + cust_name);
            console.log("cust_source = " + cust_source);
            console.log("cust_industry = " + cust_industry);
            console.log("cust_level = " + cust_level);
            console.log("cust_linkman = " + cust_linkman);
            console.log("cust_phone = " + cust_phone);
            console.log("cust_mobile = " + cust_mobile);
            console.log("cust_zipcode = " + cust_zipcode);
            console.log("cust_address = " + cust_address);
            $.post(
                "${pageContext.request.contextPath }/updateCustomer.action",
                {
                	"cust_id" : cust_id,
                	"cust_name" : cust_name,
                	"cust_source" : cust_source,
                	"cust_industry" : cust_industry,
                	"cust_level" : cust_level,
                	"cust_linkman" : cust_linkman,
                	"cust_phone" : cust_phone,
                	"cust_mobile" : cust_mobile,
                	"cust_zipcode" : cust_zipcode,
                	"cust_address" : cust_address
                },
                function(data){
                
                	if(data == "OK"){
                		// 修改完成后，跳转到查询页面
                		$(location).attr("href", document.referrer); // 获取 当前页面上一个页面
                	}
                }
            );
        }
    </script>
</body>

</html>